<template>
  <TableView
    ref="tableView"
    :table-attrs="{ api: getList, descs: ['create_time'], dicOptions: [{ prop: 'status', dicType: 'receive_status' }] }"
    form-path="/asset/receive/withdrawalForm/{id:-1}"
    :search-model="searchForm"
    :delete-api="batchDelete"
    :toolbar-attrs="{
      buttons: ['slot', { del: 'receive_receive_del', create: 'receive_receive_add' }]
    }">
    <template #toolbar-button="{selectedRows}">
      <ToolbarButton
        privilege="receive_receive_export"
        type="primary"
        icon="el-icon-download"
        label="导出"
        @click="exportExcel()" />
      <ToolbarButton icon="el-icon-printer" type="primary" label="打印" :disabled="selectedRows.length !== 1" @click="assetPrint(selectedRows)" />
    </template>
    <template #columns>
      <TableColumn label="状态" prop="status" width="60" />
      <TableColumn label="退库单号" clickable prop="caseid" width="135" />
      <TableColumn label="退库时间" prop="createTime" width="90">
        <template #default="{ row }">
          {{ $formatDate(row.createTime) }}
        </template>
      </TableColumn>
      <TableColumn label="退库单位" prop="deptFullname" width="160" />
      <TableColumn label="出库时间" prop="createTime" width="90">
        <template #default="{ row }">
          {{ $formatDate(row.createTime) }}
        </template>
      </TableColumn>
      <TableColumn label="出库人" prop="createBy" width="80" />
      <TableColumn label="退库仓库" prop="outhouseName" width="100" />
      <TableColumn label="存放房间" prop="inhouseName" width="100" />
      <TableColumn label="存放位置" prop="inlocationName" width="100" />
      <TableColumn label="总价格" prop="amount" width="80" />
      <TableColumn label="退库说明" prop="explains" />
      <TableColumn label="退库明细" prop="detailed" />
    </template>
    <template #search-form>
      <FormSelect v-model="searchForm.status" dict-type="purchaseapply_status" label="状态" prop="status" />
      <FormInput v-model="searchForm.caseid" label="退库单号" prop="caseid" />
      <FormInput v-model="searchForm.createBy" label="制单人" prop="createBy" />
      <FormInput v-model="searchForm.amount" label="入库金额" prop="amount" />
      <FormDatePicker v-model="searchForm.createTime" label="退库日期" :split="false" date-range prop="createTime" />
      <FormDatePicker v-model="searchForm.outTime" label="出库日期" :split="false" date-range prop="outTime" />
      <FormInput v-model="searchForm.userName" label="使用人" prop="userName" />
      <FormInput v-model="searchForm.houseName" label="存放房间" prop="houseName" />
      <FormInput v-model="searchForm.cardName" label="资产名称" prop="cardName" />
      <FormInput v-model="searchForm.cardCode" label="资产编码" prop="cardCode" />
      <FormInput v-model="searchForm.barcode" label="商品条码" prop="barcode" />
      <FormInput v-model="searchForm.model" label="规格型号" prop="model" />
      <FormInput v-model="searchForm.quantity" label="入库数量" prop="quantity" />
      <FormInput v-model="searchForm.detailed" label="退库明细" prop="detailed" />
    </template>
  </TableView>
</template>

<script>
  import { services } from '@/config'
  import { fetchList, batchDelete } from '@/api/asset/receive'
  import { printReport } from '@/util/print'

  export default {
    name: 'WithdrawalView',
    data() {
      return {
        searchForm: {
          type: '1',
          status: '',
          caseid: '',
          createBy: '',
          amount: '',
          createTime: [],
          outTime: [],
          userName: '',
          houseName: '',
          cardName: '',
          cardCode: '',
          barcode: '',
          model: '',
          detailed: '',
          quantity: ''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
        }
      }
    },
    methods: {
      batchDelete,
      getList() {
        return fetchList(Object.assign(this.page, this.searchForm))
      },
      assetPrint(selectedRows) {
        printReport(selectedRows[0], '请选择退库信息！', 'oss_withdrawal.ureport.xml')
      },
      exportExcel() {
        this.$downBlobFile(
          `${services.assetService}receive/export`,
          this.searchForm,
          `资产退库${this.$dateFormat(new Date())}.xlsx`
        )
      }
    }
  }
</script>
